package com.qipay.baas.mapper;

import com.qipay.baas.model.CpInfo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

public interface CpInfoMapper {
    @Delete({
        "delete from cp_info",
        "where cp_id = #{cpId,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long cpId);

    @Insert({
        "insert into cp_info (cp_id, `name`, ",
        "legal_person, legal_person_idcard1, ",
        "legal_person_idcard2, business_license_no, ",
        "business_license_pic, org_code_license, ",
        "mail, addr, url, ",
        "industry, contacts, ",
        "contacts_tel, contacts_mobile)",
        "values (#{cpId,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR}, ",
        "#{legalPerson,jdbcType=VARCHAR}, #{legalPersonIdcard1,jdbcType=VARCHAR}, ",
        "#{legalPersonIdcard2,jdbcType=VARCHAR}, #{businessLicenseNo,jdbcType=VARCHAR}, ",
        "#{businessLicensePic,jdbcType=VARCHAR}, #{orgCodeLicense,jdbcType=VARCHAR}, ",
        "#{mail,jdbcType=VARCHAR}, #{addr,jdbcType=VARCHAR}, #{url,jdbcType=VARCHAR}, ",
        "#{industry,jdbcType=VARCHAR}, #{contacts,jdbcType=VARCHAR}, ",
        "#{contactsTel,jdbcType=VARCHAR}, #{contactsMobile,jdbcType=VARCHAR})"
    })
    int insert(CpInfo record);

    @InsertProvider(type=CpInfoSqlProvider.class, method="insertSelective")
    int insertSelective(CpInfo record);

    @Select({
        "select",
        "cp_id, `name`, legal_person, legal_person_idcard1, legal_person_idcard2, business_license_no, ",
        "business_license_pic, org_code_license, mail, addr, url, industry, contacts, ",
        "contacts_tel, contacts_mobile",
        "from cp_info",
        "where cp_id = #{cpId,jdbcType=BIGINT}"
    })
    @Results({
        @Result(column="cp_id", property="cpId", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="legal_person", property="legalPerson", jdbcType=JdbcType.VARCHAR),
        @Result(column="legal_person_idcard1", property="legalPersonIdcard1", jdbcType=JdbcType.VARCHAR),
        @Result(column="legal_person_idcard2", property="legalPersonIdcard2", jdbcType=JdbcType.VARCHAR),
        @Result(column="business_license_no", property="businessLicenseNo", jdbcType=JdbcType.VARCHAR),
        @Result(column="business_license_pic", property="businessLicensePic", jdbcType=JdbcType.VARCHAR),
        @Result(column="org_code_license", property="orgCodeLicense", jdbcType=JdbcType.VARCHAR),
        @Result(column="mail", property="mail", jdbcType=JdbcType.VARCHAR),
        @Result(column="addr", property="addr", jdbcType=JdbcType.VARCHAR),
        @Result(column="url", property="url", jdbcType=JdbcType.VARCHAR),
        @Result(column="industry", property="industry", jdbcType=JdbcType.VARCHAR),
        @Result(column="contacts", property="contacts", jdbcType=JdbcType.VARCHAR),
        @Result(column="contacts_tel", property="contactsTel", jdbcType=JdbcType.VARCHAR),
        @Result(column="contacts_mobile", property="contactsMobile", jdbcType=JdbcType.VARCHAR)
    })
    CpInfo selectByPrimaryKey(Long cpId);

    @UpdateProvider(type=CpInfoSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(CpInfo record);

    @Update({
        "update cp_info",
        "set `name` = #{name,jdbcType=VARCHAR},",
          "legal_person = #{legalPerson,jdbcType=VARCHAR},",
          "legal_person_idcard1 = #{legalPersonIdcard1,jdbcType=VARCHAR},",
          "legal_person_idcard2 = #{legalPersonIdcard2,jdbcType=VARCHAR},",
          "business_license_no = #{businessLicenseNo,jdbcType=VARCHAR},",
          "business_license_pic = #{businessLicensePic,jdbcType=VARCHAR},",
          "org_code_license = #{orgCodeLicense,jdbcType=VARCHAR},",
          "mail = #{mail,jdbcType=VARCHAR},",
          "addr = #{addr,jdbcType=VARCHAR},",
          "url = #{url,jdbcType=VARCHAR},",
          "industry = #{industry,jdbcType=VARCHAR},",
          "contacts = #{contacts,jdbcType=VARCHAR},",
          "contacts_tel = #{contactsTel,jdbcType=VARCHAR},",
          "contacts_mobile = #{contactsMobile,jdbcType=VARCHAR}",
        "where cp_id = #{cpId,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(CpInfo record);
}